package com.mangofactory.aop.aspects
{
	import com.mangofactory.aop.joinpoints.ProceedingJoinPoint;
	
	import flash.utils.getQualifiedSuperclassName;
	import flash.utils.getTimer;
	
	import mx.logging.Log;
	
	public class TimerAspect implements Aspect
	{
		public function intercept(pointCut:ProceedingJoinPoint):void
		{
			var startTime:int = getTimer();
			pointCut.proceed();
			var endTime:int = getTimer();
			logMethodDuration(endTime - startTime,pointCut); 
		}

		private function logMethodDuration(duration:int, pointCut:ProceedingJoinPoint):void
		{
			var category:String = getQualifiedSuperclassName(pointCut.targetInstance);
			category = category.replace("::",".")
			Log.getLogger(category).info("{0} completed in {1}ms",pointCut.targetMember.toString(),duration.toString());
		}
	}
}